ROXIE Magnetic

Import Libraries

import os
from pathlib import Path
import sys
import scrapbook as sb
import plotly.offline as po
# Set notebook mode to work in offline
po.init_notebook_mode(connected=False)

from magnumapi.geometry.GeometryFactory import GeometryFactory
from magnumapi.geometry.roxie.CableDatabase import CableDatabase
from magnumapi.tool_adapters.roxie.RoxieToolAdapter import RoxieToolAdapter
from magnumapi.tool_adapters.roxie.RoxieInputBuilder import RoxieInputBuilder
import magnumapi.tool_adapters.roxie.RoxieAPI as RoxieAPI
Analysis executed on 2021-08-09 14:05:01
Loaded MagNum API version 0.0.1
Loaded Tool Adapter version 0.0.1 for ROXIE VERS.10, UPDATE 3.1, 2015

Input Parameters

cadata_abs_path = os.path.join(Path(os.getcwd()).parent.absolute(), 'input/roxieold_2.cadata')
model_input_rel_path = '../input/16T_rel.json'
target_field = 16
input_rel_path = 'input'
full_output = True
# Parameters
full_output = "True"

Build Geometry

cadata = CableDatabase.read_cadata(cadata_abs_path)
geometry = GeometryFactory.init_with_json(model_input_rel_path, cadata)
geometry.build_blocks()
roxie_df = geometry.to_roxie_df()
roxie_df
no type nco radius phi alpha current condname n1 n2 imag turn
0 1 1 4 25.00 0.57294 -1.177972e-16 13500 16TIL9 2 20 0 0
1 2 1 5 25.00 23.00000 2.600000e+01 13500 16TIL9 2 20 0 0
2 3 1 2 25.00 50.80000 4.700000e+01 13500 16TIL9 2 20 0 0
3 4 1 2 25.00 65.50000 6.600000e+01 13500 16TIL9 2 20 0 0
4 5 1 7 39.00 0.36728 -1.177972e-16 13500 16TIL9 2 20 0 0
5 6 1 10 39.00 26.00000 3.500000e+01 13500 16TIL9 2 20 0 0
6 7 1 2 39.00 61.00000 5.400000e+01 13500 16TIL9 2 20 0 0
7 8 1 18 53.00 0.27026 -1.139973e-16 13500 16TOL8 2 20 0 0
8 9 1 9 53.00 31.30000 3.000000e+01 13500 16TOL8 2 20 0 0
9 10 1 2 53.00 57.00000 5.000000e+01 13500 16TOL8 2 20 0 0
10 11 1 28 67.45 0.21236 -1.139973e-16 13500 16TOL8 2 20 0 0
11 12 1 11 67.45 37.90000 3.000000e+01 13500 16TOL8 2 20 0 0

Plot Geometry

geometry.build_blocks()
    
if full_output:
    geometry.plotly_blocks(figsize=(85, 85), xlim=(0, 85), ylim=(0, 85))

Write Cadata File

cadata.write_cadata(cadata_abs_path)

Build ROXIE input

roxie_input = RoxieInputBuilder()
roxie_input.cadata_path = cadata_abs_path
roxie_input.block = geometry.to_roxie_df()
roxie_input.set_flag('LFORCE2D', True)
roxie_input.build(os.path.join(input_rel_path, 'template.roxie'), 
                  os.path.join(input_rel_path, 'input.data'))

Run ROXIE

roxie = RoxieToolAdapter(os.path.join(input_rel_path, 'input.data'), 
                         os.path.join(input_rel_path, 'input.output'))

roxie.run()

Plot Results

if full_output:
    xml_path = os.path.join(input_rel_path, 'roxieData.xml')
    roxie.correct_xml_file(xml_path, xml_path)
    strand_data = roxie.parse_roxie_xml(xml_path)
    roxie.plotly_results(strand_data)

Display Figures of Merit

fom_df = roxie.read_figures_of_merit_table()
fom_dct = roxie.convert_figures_of_merit_to_dict(fom_df)
fom_df
S1 S2 OPER OBJECTIVE.1 WEIGHTED OBJ
OBJECTIVE
B 3 1 MINABS -10.180 1.0180
B 5 1 MINABS -1.531 0.1531
MARGMI 0 0 =2 0.000 225.0000
BIGB 1 1 =2 -16.600 5.1180

Scale Lorentz Force with Peak Field

roxie.update_force2d_with_field_scaling(os.path.join(input_rel_path, 'roxie.force2d'),
                                        os.path.join(input_rel_path, 'roxie_scaled.force2d'),
                                        abs(fom_dct['bigb']),
                                        target_field)

Save Figures of Merit as an Output

fom_dct['b3'] = abs(fom_dct['b3'])
fom_dct['b5'] = abs(fom_dct['b5'])
fom_dct['margmi'] *= (abs(fom_dct['bigb']) / target_field)
sb.glue('model_results', data=fom_dct, encoder='json')